using System;
using System.ComponentModel.DataAnnotations;
using Abp.Auditing;
using Abp.Authorization.Users;
using Abp.AutoMapper;
using Abp.Runtime.Validation;
using FwProject.Authorization.Users;

namespace FwProject.Users.Dto
{
    [AutoMapTo(typeof(User))]
    public class CreateUserDto : IShouldNormalize
    {
        [Display(Name="所属工厂")]
        public Guid? FactoryinfoId { get; set; }


        [RegularExpression(@"^[a-zA-Z\d]+$",ErrorMessage ="格式输入错误，只能为数字和英文小写字母！")]
        [Required(ErrorMessage = "{0}不能为空")]
        [StringLength(AbpUserBase.MaxUserNameLength,ErrorMessage ="不能超过{1}个字符")]
        [Display(Name ="用户名")]
        public string UserName { get; set; }

        [Required(ErrorMessage = "{0}不能为空")]
        [StringLength(AbpUserBase.MaxNameLength, ErrorMessage = "不能超过{1}个字符")]
        [Display(Name = "姓名")]
        public string Name { get; set; }

        [Required(ErrorMessage = "{0}不能为空")]
        [StringLength(AbpUserBase.MaxSurnameLength, ErrorMessage = "不能超过{1}个字符")]
        [Display(Name = "姓")]
        public string Surname { get; set; }

        [Required(ErrorMessage = "{0}不能为空")]
        [EmailAddress]
        [StringLength(AbpUserBase.MaxEmailAddressLength, ErrorMessage = "不能超过{1}个字符")]
        [Display(Name="邮箱")]
        public string EmailAddress { get; set; } = $"123{System.DateTime.Now.ToString("yyyymmddhhmmss")}@oa.com";

        public bool IsActive { get; set; } = true;

        [Display(Name="角色")]
        public string[] RoleNames { get; set; }

        [Required(ErrorMessage = "{0}不能为空")]
        [StringLength(AbpUserBase.MaxPlainPasswordLength, ErrorMessage = "不能超过{1}个字符")]
        [DisableAuditing]
        [Display(Name = "密码")]
        public string Password { get; set; }
        [StringLength(AbpUserBase.MaxPlainPasswordLength, ErrorMessage = "不能超过{1}个字符")]
        [Display(Name = "微信扫码")]
        public string OpenId_Code { get; set; }
        [StringLength(AbpUserBase.MaxPlainPasswordLength, ErrorMessage = "不能超过{1}个字符")]
        [Display(Name = "微信的链接码")]
        public string OpenId_Public { get; set; }
        [StringLength(AbpUserBase.MaxPlainPasswordLength, ErrorMessage = "不能超过{1}个字符")]
        [Display(Name = "微信公共码")]
        public string Unionid { get; set; }
        [StringLength(AbpUserBase.MaxPlainPasswordLength, ErrorMessage = "不能超过{1}个字符")]
        [Display(Name = "真实姓名")]
        public string Realname { get; set; }
        [StringLength(AbpUserBase.MaxPlainPasswordLength, ErrorMessage = "不能超过{1}个字符")]
        [Display(Name = "当前地址")]
        public string NowAddress { get; set; }
        [StringLength(AbpUserBase.MaxPlainPasswordLength, ErrorMessage = "不能超过{1}个字符")]
        [Display(Name = "头像")]
        public string Face { get; set; }
        [StringLength(AbpUserBase.MaxPlainPasswordLength, ErrorMessage = "不能超过{1}个字符")]

        [RegularExpression(@"^1\d{10}$",ErrorMessage ="格式输入错误，只能为11位纯数字！")]
        [Required(ErrorMessage = "{0}不能为空")]
        [Display(Name = "手机号码")]
        public string Mobile { get; set; }
        [Display(Name = "用户类型")]
        public EmployeeType EmployeeType { get; set; } = EmployeeType.员工类型;

        public void Normalize()
        {
            if (RoleNames == null)
            {
                RoleNames = new string[0];
            }
        }
    }
}
